
/* 
 * Copyright 2001-2009 Terracotta, Inc. 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 * use this file except in compliance with the License. You may obtain a copy 
 * of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 *   
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
 * License for the specific language governing permissions and limitations 
 * under the License.
 * 
 */

package org.quartz;

import java.util.Date;

public class SchedulerMetaData implements java.io.Serializable {


    private String schedName;

    private String schedInst;

    private Class schedClass;

    private boolean isRemote;

    private boolean started;

    private boolean isInStandbyMode;

    private boolean shutdown;

    private Date startTime;

    private int numJobsExec;

    private Class jsClass;

    private boolean jsPersistent;

    private boolean jsClustered;

    private Class tpClass;

    private int tpSize;

    private String version;

    public SchedulerMetaData(String schedName, String schedInst,
            Class schedClass, boolean isRemote, boolean started,
            boolean isInStandbyMode, boolean shutdown, Date startTime, int numJobsExec,
            Class jsClass, boolean jsPersistent, boolean jsClustered, Class tpClass, int tpSize,
            String version) {
        this.schedName = schedName;
        this.schedInst = schedInst;
        this.schedClass = schedClass;
        this.isRemote = isRemote;
        this.started = started;
        this.isInStandbyMode = isInStandbyMode;
        this.shutdown = shutdown;
        this.startTime = startTime;
        this.numJobsExec = numJobsExec;
        this.jsClass = jsClass;
        this.jsPersistent = jsPersistent;
        this.jsClustered = jsClustered;
        this.tpClass = tpClass;
        this.tpSize = tpSize;
        this.version = version;
    }

    public String getSchedulerName() {
        return schedName;
    }

    public String getSchedulerInstanceId() {
        return schedInst;
    }

    public Class getSchedulerClass() {
        return schedClass;
    }

    public Date getRunningSince() {
        return startTime;
    }
    
    public int getNumberOfJobsExecuted() {
        return numJobsExec;
    }

    public boolean isSchedulerRemote() {
        return isRemote;
    }

    public boolean isStarted() {
        return started;
    }

    public boolean isInStandbyMode() {
        return isInStandbyMode;
    }

    public boolean isShutdown() {
        return shutdown;
    }

    public Class getJobStoreClass() {
        return jsClass;
    }

    public boolean jobStoreSupportsPersistence() {
        return isJobStoreSupportsPersistence();
    }
    
    public boolean isJobStoreSupportsPersistence() {
        return jsPersistent;
    }

    public boolean isJobStoreClustered() {
        return jsClustered;
    }

    public Class getThreadPoolClass() {
        return tpClass;
    }

    public int getThreadPoolSize() {
        return tpSize;
    }

    public String getVersion() {
        return version;
    }

    public String toString() {
        try {
            return getSummary();
        } catch (SchedulerException se) {
            return "SchedulerMetaData: undeterminable.";
        }
    }

    public String getSummary() throws SchedulerException {
        StringBuffer str = new StringBuffer("Quartz Scheduler (v");
        str.append(getVersion());
        str.append(") '");

        str.append(getSchedulerName());
        str.append("' with instanceId '");
        str.append(getSchedulerInstanceId());
        str.append("'\n");

        str.append("  Scheduler class: '");
        str.append(getSchedulerClass().getName());
        str.append("'");
        if (isSchedulerRemote()) {
            str.append(" - access via RMI.");
        } else {
            str.append(" - running locally.");
        }
        str.append("\n");

        if (!isShutdown()) {
            if (getRunningSince() != null) {
                str.append("  Running since: ");
                str.append(getRunningSince());
            } else {
                str.append("  NOT STARTED.");
            }
            str.append("\n");

            if (isInStandbyMode()) {
                str.append("  Currently in standby mode.");
            } else {
                str.append("  Not currently in standby mode.");
            }
        } else {
            str.append("  Scheduler has been SHUTDOWN.");
        }
        str.append("\n");

        str.append("  Number of jobs executed: ");
        str.append(getNumberOfJobsExecuted());
        str.append("\n");

        str.append("  Using thread pool '");
        str.append(getThreadPoolClass().getName());
        str.append("' - with ");
        str.append(getThreadPoolSize());
        str.append(" threads.");
        str.append("\n");

        str.append("  Using job-store '");
        str.append(getJobStoreClass().getName());
        str.append("' - which ");
        if (isJobStoreSupportsPersistence()) {
            str.append("supports persistence.");
        } else {
            str.append("does not support persistence.");
        }
        if (isJobStoreClustered()) {
            str.append(" and is clustered.");
        } else {
            str.append(" and is not clustered.");
        }
        str.append("\n");

        return str.toString();
    }

}
